function ListNode(val, next) {
  this.val = (val === undefined ? 0 : val)
  this.next = (next === undefined ? null : next)
}


function reverseList(head) {
  let pre = null,
      next = null

  while (head !== null) {
    next = head.next
    head.next = pre
    pre = head
    head = next
  }
  return pre
}

